package com.ytf.test.eighth;

/**
 * @author: YTF
 * @date: 2025/1/24 16:50
 * @version: 1.0
 * @description:
 */
class Meal{
    public Meal() {
        System.out.println("Meal()");
    }
}
class Bread{

    static {
        System.out.println("static Bread");
    }
    public Bread() {
        System.out.println("Bread()");
    }
}
class Cheese{
    public Cheese() {
        System.out.println("Cheese()");
    }
}
class Lettuce{
    public Lettuce() {
        System.out.println("Lettuce()");
    }
}
class Lunch extends Meal{
    public Lunch() {
        System.out.println("Lunch()");
    }
}
class PortableLunch extends Lunch{
    public PortableLunch() {
        System.out.println("PortableLunch()");
    }
}
public class Sandwich extends PortableLunch {

    static {
        System.out.println("static Sandwich");
    }
    private static Bread bread= new Bread();

    {
        System.out.println("方法块");
    }
    private Cheese cheese = new Cheese();
    private Lettuce lettuce = new Lettuce();


    public Sandwich() {
        System.out.println("Sandwich()");
    }

    public static void main(String[] args) {
        System.out.println("main()");
        Sandwich sandwich = new Sandwich();
        /**
         * Output:
         * Meal()
         * Lunch()
         * PortableLunch()
         * Bread()
         * Cheese()
         * Lettuce()
         * Sandwich()
         *
         * static Sandwich
         * static Bread
         * Bread()
         * main()
         * Meal()
         * Lunch()
         * PortableLunch()
         * 方法块
         * Cheese()
         * Lettuce()
         * Sandwich()
         *
         * 总结：
         * 静态-》父类-》当前类-》构造器
         */
    }
}
